package com.lkf.rpc;

import com.lkf.rpc.service.InfoService;
import com.lkf.rpc.service.UserService;
import com.lkf.rpc.stub.RPCClientProxy;

/**
 * 客户端远程启动RPC远程调用
 */
public class CallRPC {
    public static void main(String[] args) {
        // 远程调用接口包名
        String packageName = "com.lkf.rpc.service";
        // 调用地址
        String address = "127.0.0.1";
        // 调用端口
        int port = 9999;
        // 远程调用
        UserService userService = (UserService) RPCClientProxy.create(UserService.class, packageName, address, port);
        // 打印调用结果
        System.out.println(userService.getUserStr("lkf"));

        // 错误的调用示例，服务端没有对应接口类
        // 远程调用接口包名
        String packageName2 = "com.lkf.rpc.service";
        // 远程调用
        InfoService infoService = (InfoService) RPCClientProxy.create(InfoService.class, packageName2, address, port);
        // 打印调用结果
        System.out.println(infoService.getInfo("lkf"));

        // 错误的调用示例，调用包路径与服务端不一致
        // 远程调用接口包名
        String packageName3 = "com.lkf.rpc.service2";
        // 远程调用
        UserService userService2 = (UserService) RPCClientProxy.create(UserService.class, packageName3, address, port);
        // 打印调用结果
        System.out.println(userService2.getUserStr("lkf"));
    }
}
